<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>{$pagetitle}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
	<link rel="stylesheet" href="/static/admin/style/global.css" media="all">
	<!--select2 js start-->
	<link rel="stylesheet" href="/static/select2/select2.css" media="all">
	<!--select2 js end-->
	<link rel="stylesheet" href="/static/fancybox3/jquery.fancybox.min.css" media="all">
	<link rel="stylesheet" href="/static/admin/style/model38.css" media="all">

</head>
<body>

<div class="layui-fluid">
	<div class="layui-card">

		<div class="layui-form-header">
			<div class="header-left" style="width:70%">
				<div class="layui-inline set-select2">
					<select name="catid" class="select2" lay-ignore style="min-width:220px;" onchange="goLink(this)">{$catOption|raw}</select>
					<a class="layui-btn {$state=='0'?'':'layui-btn-primary'}" href="{:url('index',['catid'=>$cat['catid']])}"><i class="layui-icon layui-icon-ok-circle"></i> 待发布({$DataCount.index})</a>
					<a class="layui-btn {$state=='1'?'':'layui-btn-primary'}" href="{:url('index',['catid'=>$cat['catid'],'state'=>1])}"><i class="layui-icon layui-icon-ok-circle"></i> 已发布({$DataCount.Published})</a>
					<a class="layui-btn {$state=='readyCheck'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'readyCheck'])}"><i class="layui-icon layui-icon-fonts-clear"></i> 待他人审核({$DataCount.readyCheck})</a>
					<a class="layui-btn {$state=='notCheck'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'notCheck'])}"><i class="layui-icon layui-icon-close"></i> 审核不通过({$DataCount.notCheck})</a>
					<a class="layui-btn {$state=='readyCheckPublic'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'readyCheckPublic'])}"><i class="layui-icon layui-icon-fonts-clear"></i> 审核公海({$DataCount.readyCheckPublic})</a>
					<a class="layui-btn {$state=='draft'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'draft'])}"><i class="layui-icon layui-icon-edit"></i> 我的草稿({$DataCount.draft})</a>
					<a class="layui-btn {$state=='public'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'public'])}"><i class="layui-icon layui-icon-edit"></i> 创作公海({$DataCount.public})</a>
					<a class="layui-btn {$state=='recycle'?'':'layui-btn-primary'}" href="{:url('index_cache',['catid'=>$cat['catid'],'state'=>'recycle'])}"><i class="layui-icon layui-icon-delete"></i> 回收站({$DataCount.recycle})</a>
				</div>
			</div>

			<div class="header-right" style="width:30%;">
				<div class="layui-inline">
					{if $Request.param.openSearch}
					<a href="{:url('',['catid'=>$cat['catid'],'openSearch'=>0,'state'=>$state])}" class="layui-btn layui-btn-primary layuiadmin-btn-list"><i class="layui-icon layui-icon-up"></i> 关闭搜索</a>
					{else /}
					<a href="{:url('',['catid'=>$cat['catid'],'openSearch'=>1,'state'=>$state])}" class="layui-btn layui-btn-primary layuiadmin-btn-list"><i class="layui-icon layui-icon-down"></i> 展开搜索</a>
					{/if}

					<a class="layui-btn layui-btn-primary layuiadmin-btn-list iframe" href="{:url('InfoImport/index',['catid'=>$cat['catid'],'state'=>'checked'])}" data-width="100%" data-height="100%"><i class="layui-icon layui-icon-app"></i> 导入</a>
					<a class="layui-btn layui-btn-primary layuiadmin-btn-list" onclick="export_info()"><i class="layui-icon layui-icon-export"></i> 导出</a>
					<a class="layui-btn" href="{:url('add',['catid'=>$cat['catid']])}"><i class="layui-icon layui-icon-addition"></i> 增加信息</a>
				</div>
			</div>
			<div class="clear"></div>
			{if $Request.param.openSearch}
			<form action="{:url()}" method="get">
				<input type="hidden" name="catid" value="{$cat.catid}" />
				<input type="hidden" name="state" value="{$state}" />
				<input type="hidden" name="openSearch" value="1" />
				<div  class="layui-form layui-form-item info-search">
					<div class="layui-inline search-field">
						<label class="layui-form-label">
							<select lay-ignore name="searchField">
								{foreach $SearchFieldInc as $v}
								<option value="{$v.field}" {if $Request.param.searchField==$v.field}selected{/if}>{$v.name}</option>
								{/foreach}

							</select>
						</label>
						<label class="layui-form-label" style="width: 80px;">
							<select lay-ignore name="searchFilter">
								<option value="like" {if $Request.param.searchFilter=='like'}selected{/if}>包含</option>
								<option value="notlike" {if $Request.param.searchFilter=='notlike'}selected{/if}>不包含</option>
								<option value="all" {if $Request.param.searchFilter=='all'}selected{/if}>完全匹配</option>
								<option value="eq" {if $Request.param.searchFilter=='eq'}selected{/if}>等于</option>
								<option value="neq" {if $Request.param.searchFilter=='neq'}selected{/if}>不等于</option>
								<option value="gt" {if $Request.param.searchFilter=='gt'}selected{/if}>大于</option>
								<option value="egt" {if $Request.param.searchFilter=='egt'}selected{/if}>大于等于</option>
								<option value="lt" {if $Request.param.searchFilter=='lt'}selected{/if}>小于</option>
								<option value="elt" {if $Request.param.searchFilter=='elt'}selected{/if}>小于待于</option>
							</select>
						</label>
						<div class="layui-input-inline">
							<input type="text" name="keywords" value="{$Request.param.keywords}" placeholder="请输入" autocomplete="off" class="layui-input">
						</div>
					</div>

					<div class="layui-inline" style="width:300px; margin-left: 20px;">
						<div class="layui-input-block">
							<input type="checkbox" name="is_top" value="1" {if $Request.param.is_top}checked{/if} title="置顶">
							<input type="checkbox" name="is_good" value="1" {if $Request.param.is_good}checked{/if} title="推荐">
							<input type="checkbox" name="thumb" value="1" {if $Request.param.thumb}checked{/if} title="缩略图">
						</div>
					</div>


					<div class="layui-inline" style="width:400px">
						<label class="layui-form-label">时间</label>
						<div class="layui-input-inline" style="margin-right: 0px;">
							<input type="text" name="start_time" value="{$Request.param.start_time}" autocomplete="off" class="layui-input" id="test-laydate-start" placeholder="开始日期">
						</div>

						<div class="layui-input-inline">
							<input type="text" name="end_time" value="{$Request.param.end_time}" autocomplete="off" class="layui-input" id="test-laydate-end" placeholder="结束日期">
						</div>
					</div>

					<div class="layui-inline" style="float: right; width: auto; margin-right: 0px;">
						<button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
							<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 开始搜索
						</button>
						<a href="{:url('',['catid'=>$cat['catid'],'openSearch'=>0])}" class="layui-btn layui-btn-primary layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
							<i class="layui-icon layui-icon-close layuiadmin-button-btn"></i> 关闭搜索功能
						</a>
					</div>
				</div>
			</form>

			{/if}
		</div>


		<div class="layui-card-body" style="background: #f2f2f2; padding: 0">
			<form class="layui-form" action="{:url('updateSort')}" method="post" onsubmit="return save_form(this)" lay-filter="component-form-element">
				<input type="hidden" name="catid" value="{$cat.catid}">


				<div class="XhsBox">
					{foreach $data as $key=>$v}
					<div class="XhsBox_list">
						<div class="XhsBox_list_img">
							<div class="layui-carousel carousel-container">
								<div carousel-item="">
									<?php
									$morepic=str2arr($v['morepic'],"\r\n","||");

									foreach($morepic as $vs){
									?>
									<a data-fancybox="images" href="<?=$vs[1]?>" class="list_img_li"><img src="<?=$vs[1]?>"></a>
									<?php
									}
									?>
								</div>
							</div>
						</div>
						<div class="XhsBox_list_content">
							<div class="list_content_title">{$v.title}</div>
							<div class="list_content_txt">{$v.content|nl2br|raw}</div>
						</div>
						<div class="XhsBox_list_btn">
							<div class="list_btn_left">
								<div class="btn_left_li CopyTitle" title="点击复制">标题</div>
								<div class="btn_left_li CopyTxt" title="点击复制">内容</div>
								<div class="btn_left_li DownloadImg" title="打包下载">图片</div>
								{if $v.state==0}
								<a href="{:url('update',array('catid'=>$v['catid'],'id'=>$v['id']))}" class="btn_left_li" style="margin-left: 40px; background: red">改</a>
								<a href="{:url('delete',array('catid'=>$v['catid'],'ids'=>$v['id']))}" class="btn_left_li ajax_del" style="background: red">删</a>
								{/if}
							</div>
							{if $v.state==0}
							<a href="{:url('push',array('catid'=>$v['catid'],'ids'=>$v['id']))}" data-msg="确定要设为已发布吗？" class="list_btn_right ajax_del" >设为<br>已发</a>
							{/if}
						</div>
					</div>
					{/foreach}

				</div>


				<div class="listpage">{$pagelist|raw}</div>
			</form>
		</div>

	</div>
</div>

<script src="/static/admin/layui/layui.js"></script>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/globals.js"></script>

<!--select2 js start-->
<script src="/static/select2/select2.js"></script>
<!--select2 js end-->

<script src="/static/js/jszip.min.js"></script>
<script src="/static/fancybox3/jquery.fancybox.min.js"></script>
<script>
	function applyImgOpts(containerIndex) {
		// 使用 FancyBox 初始化指定序号的 a 元素
		$('[data-fancybox="images-' + containerIndex + '"]').fancybox(imgOpts);
	}
	// 对每个循环体执行初始化
	$('.XhsBox_list').each(function (index) {
		// 为每个循环体内的 a 元素设置唯一的序号
		var containerIndex = index + 1;
		$(this).find('.XhsBox_list_img a').attr('data-fancybox', 'images-' + containerIndex);
		// 初始化 FancyBox
		applyImgOpts(containerIndex);
	});
</script>
<script>
	$('.select2').select2();
	layui.config({
		base: '/static/admin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use(['index', 'form', 'laydate', 'carousel'], function () {
		var $ = layui.$
				, admin = layui.admin
				, element = layui.element
				, laydate = layui.laydate
				, carousel = layui.carousel;
		//图片轮播
		$(".XhsBox_list").each(function(index) {
			// 为每个轮播项生成唯一的ID
			var carouselId = "carousel" + (index + 1);
			// 为当前轮播项的carousel-container元素添加唯一的ID
			$(this).find(".carousel-container").attr("id", carouselId);

			// 使用 layui.js 初始化轮播
			carousel.render({
				elem: '#' + carouselId,
				interval: 5000,
				autoplay: false,
				arrow: 'none'
			});
		});
		//示例代码
		//复制标题
		$(".CopyTitle").click(function() {
			var currentXhsBoxList = $(this).closest('.XhsBox_list');
			var titleText = currentXhsBoxList.find('.list_content_title').text();
			layer.msg("复制成功");
			copyToClipboard(titleText);
		});

		// 复制内容
		$(".CopyTxt").click(function() {
			var currentXhsBoxList = $(this).closest('.XhsBox_list');
			var contentText = currentXhsBoxList.find('.list_content_txt').text();
			layer.msg("复制成功");
			copyToClipboard(contentText);
		});
		// 下载图片
		$(".DownloadImg").click(function() {
			// 找到当前点击元素所在的父级 XhsBox_list
			var currentXhsBoxList = $(this).closest('.XhsBox_list');
			// 找到当前 XhsBox_list 内所有图片元素
			var images = currentXhsBoxList.find('.list_img_li img');
			var title=currentXhsBoxList.find('.list_content_title').html();

			// 创建 JSZip 实例
			var zip = new JSZip();

			// 遍历每张图片并将其添加到压缩包中
			images.each(function(index) {
				var imageUrl = $(this).attr('src');
				var imageName = 'image_' + (index + 1) + '.jpg';

				// 获取图片数据
				fetch(imageUrl)
						.then(response => response.blob())
						.then(blob => {
							// 将图片添加到压缩包
							zip.file(imageName, blob);

							// 如果是最后一张图片，生成并触发下载链接
							if (index === images.length - 1) {
								zip.generateAsync({ type: 'blob' })
										.then(function (content) {
											// 创建下载链接
											var link = document.createElement('a');
											link.href = URL.createObjectURL(content);
											link.download = title+'.zip';
											link.click();
										});
							}
						});
			});
		});

		function copyToClipboard(text) {
			var tempInput = $('<textarea>');
			$('body').append(tempInput);
			tempInput.val(text).select();
			document.execCommand('copy');
			tempInput.remove();

		}
		//开始日期
		var insStart = laydate.render({
			elem: '#test-laydate-start'
			,done: function(value, date){
				//更新结束日期的最小日期
				insEnd.config.min = lay.extend({}, date, {
					month: date.month - 1
				});
				//自动弹出结束日期的选择器
				insEnd.config.elem[0].focus();
			}
		});

		//结束日期
		var insEnd = laydate.render({
			elem: '#test-laydate-end'
			,min: 0
		});

	});
	//删除
	function this_delete(){
		layer.confirm("您确定要删除吗？",function(){
			$('.layui-form').attr('action','{:url("delete")}');
			$('.layui-form').submit();
		},function(){layer.closeAll();return false;});
	}
	//取消审核
	function cancel_checked(){
		layer.confirm("您确定要取消审核吗？",function(){
			$('.layui-form').attr('action','{:url("cancelChecked")}');
			$('.layui-form').submit();
		},function(){layer.closeAll();return false;});
	}
	//栏目跳转
	function goLink(obj){
		var catid=$(obj).val();
		var url="{:url('Info/index')}?catid="+catid+"&keywords=";
		window.location.href=url;
	}
	//复制信息
	function copy_info(){
		var chk_value =[];//定义一个数组    
		$('input[name="ids[]"]:checked').each(function(){
			chk_value.push($(this).val());
		});
		iframe("{:url('copy',['catid'=>$cat['catid']])}&ids="+chk_value);
	}
	//移动信息
	function move_info(){
		var chk_value =[];//定义一个数组    
		$('input[name="ids[]"]:checked').each(function(){
			chk_value.push($(this).val());
		});
		iframe("{:url('move',['catid'=>$cat['catid']])}&ids="+chk_value);
	}
	//导出
	function export_info(){
		var chk_value =[];//定义一个数组    
		$('input[name="ids[]"]:checked').each(function(){
			chk_value.push($(this).val());
		});
		iframe("{:url('export',['catid'=>$cat['catid']])}&ids="+chk_value,"800px");
	}
</script>

</body>
</html>
